package com.kz.controller;


import com.kz.entity.YcreCost;
import com.kz.service.YcreBigService;
import com.kz.service.YcreCostService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zk
 * @since 2020-11-10
 */
@RestController
@RequestMapping("/ycre-cost")
public class YcreCostController {
    @Resource
    private YcreCostService ycreCostService;
    @Resource
    private YcreBigService ycreBigService;

    @PostMapping(value = "getYcreList")
    public List<YcreCost> getYcreList(Map<String, String> map) {

        return ycreCostService.selectYcreCostByAccId(map.get("accId"));
    }


    @PostMapping(value = "saveOrUpdate")
    public String saveOrUpdate(@RequestBody YcreCost ycreCost) {
        try {
            if (ycreCost.getId() != null) {

                ycreCostService.updateById(ycreCost);

            } else {
                ycreCost.setDeleted("N");
                ycreCostService.insert(ycreCost);

            }
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "失败";
        }
    }

    @PostMapping(value = "deleted")
    public String deleted(@RequestBody Map<String, Integer> map) {

        YcreCost ycreCost = ycreCostService.selectById(map.get("id"));

        if (ycreCost != null) {
            ycreCost.setDeleted("Y");

            ycreCostService.updateById(ycreCost);
        }

        return "删除成功！！";
    }
}
